package bombermanGame;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class GamePlayState extends BasicGameState {
	
	public static int ID = 5;
	private Image background;
	private Bomberman bomberman;
	private boolean movingLeft;
	private boolean movingRight;
	private boolean movingUp;
	private boolean movingDown;
	

	@Override
	public void init(GameContainer container, StateBasedGame game)
			throws SlickException {
		bomberman = new Bomberman();
		background = new Image("/images/bomberman/background.jpg");
		movingDown = false;
		movingLeft = false;
		movingRight = false;
		movingUp = false;
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		background.draw(0, 0);
		
		Input input = container.getInput();
		
		if(input.isKeyDown(Input.KEY_UP))
			bomberman.getUpAnimation().draw(bomberman.getPosition().x, bomberman.getPosition().y);
		
		else if(input.isKeyDown(Input.KEY_DOWN))
			bomberman.getDownAnimation().draw(bomberman.getPosition().x, bomberman.getPosition().y);
		
		
		else if(input.isKeyDown(Input.KEY_LEFT))
			bomberman.getLeftAnimation().draw(bomberman.getPosition().x, bomberman.getPosition().y);	
		
		else if(input.isKeyDown(Input.KEY_RIGHT))
			bomberman.getRightAnimation().draw(bomberman.getPosition().x, bomberman.getPosition().y);
		

		else{
			if(movingDown)
				bomberman.getStandDownimage().draw(bomberman.getPosition().x, bomberman.getPosition().y);
			
			else if(movingUp)
				bomberman.getStandUpimage().draw(bomberman.getPosition().x, bomberman.getPosition().y);
			
			else if(movingLeft)
				bomberman.getStandLeftimage().draw(bomberman.getPosition().x, bomberman.getPosition().y);
			
			else if(movingRight)
				bomberman.getStandRightimage().draw(bomberman.getPosition().x, bomberman.getPosition().y);
			
			else
				bomberman.getStandRightimage().draw(bomberman.getPosition().x, bomberman.getPosition().y);
		}
			
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		Input input = container.getInput();
		
		if(input.isKeyDown(Input.KEY_UP)){
			movingUp = true;
			movingDown = false;
			bomberman.setDirectionY(-1);	
		}
		
		else if(input.isKeyDown(Input.KEY_DOWN)){
			movingDown = true;
			movingUp = false;
			bomberman.setDirectionY(1);
		}

		/*else{
			bomberman.setDirectionY(0);
			movingDown = false;
			movingUp = false;
		}*/
		
		
		else if(input.isKeyDown(Input.KEY_LEFT)){
			movingLeft = true;
			movingRight = false;
			bomberman.setDirectionX(-1);
		}
		
		else if(input.isKeyDown(Input.KEY_RIGHT)){
			movingRight = true;
			movingLeft = false;
			bomberman.setDirectionX(1);
		}
		
		else{
			bomberman.setDirectionX(0);
			bomberman.setDirectionY(0);
			//movingLeft = false;
			//movingRight = false;
		}
		
		
		bomberman.move();
	}

	@Override
	public int getID() {
		return ID;
	}

}
